//
//  PoseType.swift
//  SitPosition
//
//  Created by apple on 2019/2/3.
//  Copyright © 2019 apple. All rights reserved.
//

import Foundation


/**
 * 坐姿类型
 */
enum PoseType : CaseIterable {
    
    case ok
    case headerSlantL
    case headerSlantR
    case headerSlantRotateL
    case headerSlantRotateR
    case headerSlantLow
    case headerSlantUp
    case bodySlantL
    case bodySlantR
    case unknownSlant
    
    init?(networkValue: Int) {
        switch networkValue {
        case 1: self = PoseType.ok
        case 2: self = PoseType.headerSlantL
        case 3: self = PoseType.bodySlantL
        case 4: self = PoseType.bodySlantR
        case 5: self = PoseType.headerSlantLow
        case 6: self = PoseType.headerSlantRotateL
        case 7: self = PoseType.unknownSlant
        default: return nil
        }
    }
    
    // 反转
    var reflection: PoseType {
        switch self {
        case .ok: return .ok
        case .headerSlantL: return .headerSlantR
        case .headerSlantR: return .headerSlantL
        case .bodySlantL: return .bodySlantR
        case .bodySlantR: return .bodySlantL
        case .headerSlantLow: return .headerSlantUp
        case .headerSlantUp: return .headerSlantLow
        case .headerSlantRotateL: return .headerSlantRotateR
        case .headerSlantRotateR: return .headerSlantRotateL
        case .unknownSlant: return .unknownSlant
        }
    }
    
    // 网络协议值
    var networkValue: Int {
        switch self {
        case .ok: return 1
        case .headerSlantL, .headerSlantR: return 2
        case .bodySlantL: return 3
        case .bodySlantR: return 4
        case .headerSlantLow: return 5
        case .headerSlantRotateL, .headerSlantRotateR: return 6
        case .unknownSlant: return 7
        default: return 0
        }
    }
    
    // 是否忽略某种姿态?（暂不支持仰头姿态）
    var needIgnoreIt: Bool {
        switch self {
        case .headerSlantUp: return true
        default: return false
        }
    }
    
    // 身体姿态对应的描述
    var description: String {
        switch self {
        case .ok: return Strings.poseTypeNone
        case .headerSlantL: return Strings.poseTypeHeaderSlantL
        case .headerSlantR: return Strings.poseTypeHeaderSlantR
        case .headerSlantRotateL: return Strings.poseTypeHeaderSlantRotateL
        case .headerSlantRotateR: return Strings.poseTypeHeaderSlantRotateR
        case .headerSlantLow: return Strings.poseTypeHeaderSlantLow
        case .headerSlantUp: return Strings.poseTypeHeaderSlantUp
        case .bodySlantL: return Strings.poseTypeBodySlantL
        case .bodySlantR: return Strings.poseTypeBodySlantR
        case .unknownSlant: return Strings.poseTypeSlantUnknown
        }
    }
}


extension PoseType {
    
    var isOk: Bool {
        return self == .ok
    }
}
